<template>
  <div class="screenfull">
    <svg-icon :name="isFullscreen?'emoji':'exit-fullscreen'" @click="click" />
  </div>
</template>

<script lang="ts">
import screenfull from 'screenfull'
import SvgIcon from "../SvgIcon";
/**
 * 全屏展示组件
 */
export default {
  name: 'screenFull',
  components: {SvgIcon},
  data() {
    return {
      isFullscreen: false
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        // this.$message({ message: '你的浏览器不支持全屏', type: 'warning' })
        alert("你的浏览器不支持全屏")
        return false
      }
      screenfull.toggle()
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change)
      }
    }
  }
}
</script>

<style scoped>

</style>
